var t = getApp(),
  e = t.requirejs("core");
Page({
  data: {
    icons: t.requirejs("icons"),
    success: false,
    successData: {},
    pay_type:1,
    button_color: t.config.button_color
  },
  onLoad: function (ev) {
    e.setting();
    this.setData({
      options: ev,
      button_color: getApp().config.button_color,
      font_color: getApp().config.font_color,
      config: getApp().config
    })
      
  },
  onShow: function () {
    this.get_list()
  },
  select_pay_type:function(s){
var i=e.pdata(s).i;
console.log(i)
this.setData({pay_type:i})
  },
  /**
   *获取订单信息
   * @param order_id 订单id
   * @return array
   */
  get_list: function () {
    var t = this;
    e.get("pay/OrderInfo", { order_id: t.data.options.id}, function (i) {
      0 == i.code ? (
        t.setData({
          list: i.info,
          show: true
        })
      ): (e.alert(i.msg), setTimeout(function () {
        wx.navigateBack()
      }, 1e3))
        
    })
  },
  card_pay:function(){
    var o=this;
    e.get('Pay/cardpay',{
      out_trade_no: o.data.list.out_trade_no
    },function(t){
      if(t.code==0){
        wx.setNavigationBarTitle({
          title: "支付成功"
        });
        e.success('支付成功');
        setTimeout(function(){
          o.setData({
            success: true,
            "list.order_status": 1
          });
          //推送
          e.get('Wxpush/PayOrderPush', {
            out_trade_no: o.data.list.out_trade_no,
            formid: o.data.formid,
            uid: getApp().getCache("userinfo").uid
          }, function (aa) {
            console.log(aa)
          })
        },1000);
       
      }else{
        e.alert(t.msg);
      }
      
    },true);
  },
  /**
   *调用支付
   * @param out_trade_no 订单号
   * @param openid
   * @return array
   */
  pay: function (k) {
    var o = this;
    o.setData({
      formid: k.detail.formId
    })
    console.log(o.data.pay_type);
    if(o.data.pay_type==2){
      o.card_pay();
    }else{
      e.get("Pay/Pay", {
        out_trade_no: o.data.list.out_trade_no,
        openid: getApp().getCache("userinfo").openid
      }, function (t) {
        console.log(t)
        0 == t.code ? (
          wx.requestPayment({
            'timeStamp': t.info.timeStamp,
            'nonceStr': t.info.nonceStr,
            'package': t.info.package,
            'signType': 'MD5',
            'paySign': t.info.paySign,
            'success': function (res) {
              if (res.errMsg == "requestPayment:ok") {
                wx.setNavigationBarTitle({
                  title: "支付成功"
                });
                o.setData({
                  success: true,
                  "list.order_status": 1
                });
                //推送
                e.get('Wxpush/PayOrderPush', {
                  out_trade_no: o.data.list.out_trade_no,
                  formid: o.data.formid,
                  uid: getApp().getCache("userinfo").uid
                }, function (t) {
                  console.log(t)
                })
              } else {
                e.alert('支付失败！')
                wx.redirectTo({
                  url: "/yb_shop/pages/order/index"
                })
              }
            },
            'fail': function (res) {
              e.alert('您已经取消支付！')
              wx.redirectTo({
                url: "/yb_shop/pages/order/index"
              })
            }
          })
        ) : (e.alert(t.msg), setTimeout(function () {
          wx.navigateBack()
        }, 1e3))

      })
      return;
    }
   
   
  },
  to_home:function(){
    e.jump('/yb_shop/pages/index/index')
  },
  phone: function (t) {
    e.phone(t)
  }
})